<template>
        <div class>
          <el-card class="ep-card ep-search">
            <el-row :gutter="0">
              <el-col :span="2" style="float:right">
                <el-button type="success"  @click="save">保存</el-button>
              </el-col>
            </el-row>
          </el-card>
      
          <el-tabs type="border-card">
      
            <el-tab-pane label="贷款记录">
              <loanRecordSituation ref="loanRecordSituation" ></loanRecordSituation>
            </el-tab-pane>
      
            <el-tab-pane label="涉诉及涉执情况" name="1">
              <involvedSituation ref="involvedSituation" ></involvedSituation>
            </el-tab-pane>
      
            <el-tab-pane label="纳税记录" name="2">
              <taxRecordSituation ref="taxRecordSituation" ></taxRecordSituation>
            </el-tab-pane>
      
            <el-tab-pane label="对外担保记录" name="3">
              <externalGuaranteeSituation ref="externalGuaranteeSituation" ></externalGuaranteeSituation>
            </el-tab-pane>
            
          </el-tabs>
        </div>
      </template>
      <script>
      export default {
        components: {
          loanRecordSituation: require("./loanRecordSituation.vue").default,
          involvedSituation: require("./involvedSituation.vue").default,
          taxRecordSituation: require("./taxRecordSituation.vue").default,
          externalGuaranteeSituation: require("./externalGuaranteeSituation.vue").default,
        },
        data() {
          return {
            projId:'',
            isSaveOrUpdate:false,
          };
        },
        computed: {},
        mounted() {},
        methods: {
          init(projId){
              this.projId=projId;
              this.$api.formPost( 'biz/projLoanRecord/selectProjLoanRecord',{
                  projId:projId
                }).then(res => {
                            if(res.retHead.code=="0000000"){
                              let isSaveOrUpdate=false;
                                if(res.retBody.litigPractList.length>0){
                                  this.$refs.involvedSituation.litigPractDate=res.retBody.litigPractList;
                                  isSaveOrUpdate=true;
                                }
                                if(res.retBody.loanRecordList.length>0){
                                  this.$refs.loanRecordSituation.loadRecordData=res.retBody.loanRecordList;
                                  isSaveOrUpdate=true;
                                }
                                if(res.retBody.taxRecordList.length>0){
                                  this.$refs.taxRecordSituation.taxRecordData=res.retBody.taxRecordList;
                                  isSaveOrUpdate=true;
                                }
                                if(res.retBody.exterRecord){
                                  this.$refs.externalGuaranteeSituation.exterRecordForm=res.retBody.exterRecord;
                                  isSaveOrUpdate=true;
                                }
                                this.isSaveOrUpdate=isSaveOrUpdate;
                              }else{
                                  this.$message({
                                      type: 'error',
                                      message: res.retHead.message
                                  });
                              }
                });
            },
          save() {
            //贷款记录
            let loanRecordList = this.$refs.loanRecordSituation.getdata();
            //涉诉及涉执情况
            let litigPractList=this.$refs.involvedSituation.getdata();
            //纳税记录
            let taxRecordList=this.$refs.taxRecordSituation.getdata();
            //对外担保记录
            let exterRecord=this.$refs.externalGuaranteeSituation.getdata();
            let user=JSON.parse(sessionStorage.getItem("user"));
            let params={
              loanRecordList:loanRecordList,
              litigPractList:litigPractList,
              taxRecordList:taxRecordList,
              exterRecord:exterRecord,
              projId:this.projId,
              createUserId:user.id,
              createUserName:user.realName,
            }
            if(!this.isSaveOrUpdate){
                  this.$api.post( '/api/biz/projLoanRecord/doSaveCreditStatus',params).then(res => {
                        if(res.retHead.code=="0000000"){
                              this.$message({
                                  type: 'success',
                                  message: "保存成功"
                              });
                          //清空表单数据
                          this.$refs.loanRecordSituation.clearTable();
                          this.$refs.involvedSituation.clearTable();
                          this.$refs.taxRecordSituation.clearTable();
                          this.$refs.externalGuaranteeSituation.clearForm();
                          this.$emit("hiddenComponent");
                          }else{
                              this.$message({
                                  type: 'error',
                                  message: res.retHead.message
                              });
                          }
                      });
            }else{
              this.$api.post( '/api/biz/projLoanRecord/doUpdateCreditStatus',params).then(res => {
                        if(res.retHead.code=="0000000"){
                              this.$message({
                                  type: 'success',
                                  message: "更新成功"
                              });
                          //清空表单数据
                          this.$refs.loanRecordSituation.clearTable();
                          this.$refs.involvedSituation.clearTable();
                          this.$refs.taxRecordSituation.clearTable();
                          this.$refs.externalGuaranteeSituation.clearForm();
                          this.$emit("hiddenComponent");
                          }else{
                              this.$message({
                                  type: 'error',
                                  message: res.retHead.message
                              });
                          }
                      });
            }
            
          }
        },
        created() {}
      };
      </script>
      <style lang='scss' scoped>
      </style>